#include<set>
#include<cstdio>
#include<math.h>
#include<vector>
using namespace std;
int main(){
    //freopen("in.txt","r",stdin);
    int N,cnt,num;
    scanf("%d",&N);
    vector<set<int>> ans;
    ans.resize(N+1);
    set<int> tmp;
    for(int i=1;i<=N;i++){
        tmp.clear();
        scanf("%d",&cnt);
        for(int j=0;j<cnt;j++){
            scanf("%d",&num);
            tmp.insert(num);
        }
        ans[i]=tmp;
    }
    scanf("%d",&N);
    for(int i=0;i<N;i++){
        int a,b;
        set<int> temp;
        scanf("%d %d",&a,&b);
        int nc=0,nt=ans[b].size();
        for(auto it=ans[a].begin();it!=ans[a].end();it++){
            if(ans[b].find(*it)==ans[b].end()){nt++;}
            else{nc++;}
        }
        double result = (double)nc / nt * 100;
        printf("%.1f%%\n", result);
    }
}
